package com.littleken.foodieCommon.enums;

/**
 * @Description: 订单状态 枚举
 */
public enum OrderStatusEnum {

	WAIT_PAY(10, "待付款"),
	WAIT_DELIVER(20, "已付款，待发货"),
	WAIT_RECEIVE(30, "已发货，待收货"),
	SUCCESS(40, "交易成功"),
	CLOSE(50, "交易关闭");

	private Integer code;
	private String desc;

	OrderStatusEnum(Integer code, String desc) {
		this.code = code;
		this.desc = desc;
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	/**
	 * 通过 CODE 获取 DESC
	 * @param code
	 * @return
	 */
	public static String getDescByCode(Integer code) {
		for (OrderStatusEnum orderStatus :OrderStatusEnum.values()) {
			if (orderStatus.code.equals(code)) {
				return orderStatus.desc;
			}
		}
		return null;
	}

	/**
	 * 通过 DESC 获取 CODE
	 * @param desc
	 * @return
	 */
	public static Integer getCodeByDesc(String desc) {
		for (OrderStatusEnum orderStatus : OrderStatusEnum.values()) {
			if (orderStatus.desc.equals(desc)) {
				return orderStatus.code;
			}
		}
		return null;
	}

	/**
	 * 通过 CODE 获取 Enum
	 * @param code
	 * @return
	 */
	public static OrderStatusEnum getEnumByCode(Integer code) {
		for (OrderStatusEnum orderStatus :OrderStatusEnum.values()) {
			if (orderStatus.code.equals(code)) {
				return orderStatus;
			}
		}
		return null;
	}
}
